package yxy.game.pm2.module.tip.checker;

import java.util.HashSet;
import java.util.Set;

import yxy.apple.util.PubSub.MethodSubscriber;
import yxy.apple.util.PubSub.SubscriptionMethod;
import yxy.game.pm2.bean.currency.CurrencyType;
import yxy.game.pm2.bean.pubsub.CurrencyPublisher;
import yxy.game.pm2.bean.pubsub.CurrencyPublisher.CurrencySubscription;
import yxy.game.pm2.bean.pubsub.HeroPublisher;
import yxy.game.pm2.bean.pubsub.HeroPublisher.HeroSubscription;
import yxy.game.pm2.module.hero.HeroHandle;

public class TipSubscriber_武将 extends MethodSubscriber {

	static private TipSubscriber_武将 instance;

	public static TipSubscriber_武将 getInstance() {
		if (instance == null) {
			instance = new TipSubscriber_武将();
			instance.init();
		}
		return instance;
	}

	private void init() {
		CurrencyPublisher.getInstance().subscribe(this);
		HeroPublisher.getInstance().subscribe(this);
	}

	private TipSubscriber_武将() {
	}

	@SubscriptionMethod(Type = CurrencySubscription.class)
	public void receive(CurrencySubscription subscription) {
		String playerCode = subscription.getPlayerCode();
		if (!subscription.checkTypes(allowType())) {
			return;
		}
		new HeroHandle().updateHeroTip(playerCode);
	}

	@SubscriptionMethod(Type = HeroSubscription.class)
	public void receive(HeroSubscription subscription) {
		String playerCode = subscription.getPlayerCode();
//		Hero hero = subscription.getHero();
//		if (!new FormatHandle().heroInFormat(playerCode, hero.getCode())) {
//			return;
//		}
		new HeroHandle().updateHeroTip(playerCode);
	}

	private Set<CurrencyType> allowTypes;

	private Set<CurrencyType> allowType() {
		if (allowTypes != null) {
			return allowTypes;
		}
		allowTypes = new HashSet<>();

		allowTypes.add(CurrencyType.CT_装备);
		allowTypes.add(CurrencyType.CT_钱币);
		allowTypes.add(CurrencyType.CT_武将经验);
		allowTypes.add(CurrencyType.CT_物品);

		return allowTypes;
	}

}
